function MainIntervalAssistant(args) {
	/*
	 * this is the creator function for your scene assistant object. It will be
	 * passed all the additional parameters (after the scene name) that were
	 * passed to pushScene. The reference to the scene controller
	 * (this.controller) has not be established yet, so any initialization that
	 * needs the scene controller should be done in the setup function below.
	 */
	this.intStats = args;
}

MainIntervalAssistant.prototype.setup = function() {
	/*
	 * this function is for setup tasks that have to happen when the scene is
	 * first created
	 */

	/*
	 * use Mojo.View.render to render view templates and add them to the scene,
	 * if needed
	 */

	/* setup widgets here */

	/* add event handlers to listen to events from widgets */

	Mojo.Log.info('In Setup');

	// intStats = {
	// qSize: qNum,
	// qSound: tSound,
	// showStaff:sCleff,
	// selInt: this.myListModel.items,
	// qAnswers: []
	// };

	this.qCount = 0;
	this.radioAttribs = {};
	this.intList = [];

	Mojo.Log.info("Interval Before: " + this.intStats.selInt.items);
	// Filter out False Values

	for (z = 0; z < this.intStats.selInt.items.length; z++) {
		if (this.intStats.selInt.items[z].checked == true) {
			this.intList.push(this.intStats.selInt.items[z]);
		}
	}

	Mojo.Log.info("Interval: " + this.intList);

	// new 1.4.x HTML5 audio implementation setup
	this.libs = MojoLoader.require( {
		name : "mediaextension",
		version : "1.0"
	});
//	this.myAudioObj1 = this.controller.get('noteSound1');
//	this.myAudioObj2 = this.controller.get('noteSound2');
	this.myAudioObj1 = new Audio();
	this.myAudioObj2 = new Audio();

	// Make full screen
	this.controller.enableFullScreenMode(true);

	// Setup Choice Widget..
	this.controller.setupWidget("choiceButtons", this.radioAttribs,
			this.radioModel = {
				value : "",
				disabled : false
			});

	// ShowStaff is false so this is sound only
	if (!this.intStats.showStaff) {
		$('StaffContainer').style.display = "none";
		$('AudioContainer').style.display = "block";
		// Setup Play Widget
		this.controller.setupWidget("AudioControl", this.buttonAttribs = {},
				this.buttonModel = {
					label : "Play Again",
					disabled : false
				});

		
		Mojo.Event.listen($('AudioControl'), Mojo.Event.tap,
				this.audioPlayFirst.bind(this));

	}
	
	//Back Widget
	if(myApp.isTouchPad()){

		 var menuModel = {

		             visible: true,
		             items: [ 
		                    { icon: "back", command: "goBack"}
		             ]
		         }; 

		     this.controller.setupWidget(Mojo.Menu.commandMenu,
		         this.attributes = {
		             spacerHeight: 0,
		             menuClass: 'no-fade'
		         },
		         menuModel
		     );   

		}
	
	//Listen for first Note to End
	//this.myAudioObj1.addEventListener('ended', this.audioPlayNext.bind(this), false);
	//this.myAudioObj1.addEventListener('play', this.audioPlayNextDelay(1), false);
	
	this.createChoices();

	// Start Program
	//
	var canvas2 = $("music");
	var ctx2 = canvas2.getContext("2d");
	this.ctx2 = ctx2;
	this.nextQuestion();
};

MainIntervalAssistant.prototype.nextQuestion = function() {
	Mojo.Log.info("MainIntervalAssistan::NextQuestion::Entry");
	this.qCount++;
	var intNoteSharp = false;

	if (this.qCount > this.intStats.qSize) {
		this.endQuiz();
	} else {
		// Get and Set the Clef && Note
		this.getClef();
		selNote = this.getNote();

		// Set Global of Note
		// Probably should just do it in the function
		this.selNote = selNote;

		// Get Interval
		this.selInterval = this.intList[Math.floor(Math.random()
				* this.intList.length)];
		numSemi = semiTones[this.selInterval.iID].numSemi;
		Mojo.Log.info("Selected Interval: " + this.selInterval.iID);

		rootIdx = disp.findIndex(selNote.key);

		intNoteIdx = getSemiToneNote(rootIdx, numSemi);
		intNote = disp[intNoteIdx];

		Mojo.Log.info("Num of Interval SemiTones: " + numSemi);
		Mojo.Log.info("Selected Root Key: " + selNote.key + "::"
				+ selNote.notation);
		Mojo.Log.info("Selected Root Index: " + rootIdx);
		Mojo.Log.info("Interval Note Index: " + intNoteIdx);
		Mojo.Log.info("Interval Note: " + intNote);
		intNoteObj = getIntervalNote(intNote, "", this.selNoteIndex);
		
		
		// Set the Question Number for User
		$("qNumber").innerHTML = this.qCount;

		if (this.intStats.showStaff) {
			

			Mojo.Log.info("intObject::" + intNoteObj.key);
			// Check to see if its sound only
			//
			if (this.intStats.showStaff) {
				// Draw Staff and Notes
				drawStaff(this.ctx2, this.selClef);

				// Set Sharp
				if (intNote.indexOf("#") > 0) {
					for ( var z = 0; z < arrSharp.length; z++) {
						objSharp = arrSharp[z];
						if (objSharp.key == intNote.substring(0, 1)) {
							intSharp = objSharp;
							break;
						}
					}

					sharp(this.ctx2, intSharp.trbLocation);
				}

				// Draw Note
				if (selNote.Location > 170)
					upQuarter(this.ctx2, selNote.Location);
				else
					downQuarter(this.ctx2, selNote.Location);

				if (intNote.Location > 170)
					upQuarter2(this.ctx2, intNoteObj.Location);
				else
					downQuarter2(this.ctx2, intNoteObj.Location);
			}
		}

		this.createChoices();

		// Load Sound File
		if (intNote.indexOf("#") > 0) {
			intNoteSharp = true;
		}
		this.playSound(selNote,intNoteObj, intNoteSharp);

		// this.startTimer(this.intStats.qTime);
	}
};

MainIntervalAssistant.prototype.playSound = function(selNote, intNote, intNoteSharp) {
	
	var selNoteKey = selNote.key;
	var intNoteKey = intNote.key;
	
	var selNoteNotation = selNote.notation;
	var intNoteNotation = intNote.notation;
	
	var selNoteFile = Mojo.appPath + "sounds/" + selNoteKey + selNoteNotation + ".mp3";
	
	
	var intNoteFile = "";
	if(!intNoteSharp){
		intNoteFile = Mojo.appPath + "sounds/" + intNoteKey + intNoteNotation + ".mp3";
	}else{
		if(intNoteKey =="b"){
			Mojo.Log.info("Removing the Sharp on B and changing to c");
			intNoteKey = "c";
			intNoteFile =  Mojo.appPath + "sounds/" + intNoteKey + intNoteNotation + ".mp3";
		}else if(intNoteKey=="e"){
			Mojo.Log.info("Removing the Sharp on e and changing to f");
			intNoteKey = "f";
			intNoteFile =  Mojo.appPath + "sounds/" + intNoteKey + intNoteNotation + ".mp3";
		}else{
			intNoteFile =  Mojo.appPath + "sounds/" + intNoteKey + "#" + intNoteNotation + ".mp3";
		}
	}
	
	Mojo.Log.info("Sound File: " + selNoteFile);
	Mojo.Log.info("Sound File: " + intNoteFile);

	if (this.intStats.qSound) {
		// Load Root Audio
		this.myAudioObj1.src =selNoteFile
		this.myAudioObj1.load();

		// Load Interval Audio
		
		this.myAudioObj2.src = intNoteFile;
		this.myAudioObj2.load();

		// Play the first Note when its done the end event should fire the
		// second note.

		this.audioPlayFirst();
	}

}

MainIntervalAssistant.prototype.audioPlayFirst = function() {
	Mojo.Log.info("Audio Object Play");
	this.myAudioObj1.play();
	if(this.intStats.tChord ==2)
		this.audioPlayNextDelay(2);
	else
		this.myAudioObj2.play();
	

};

MainIntervalAssistant.prototype.audioPlayNextDelay = function(delayTime){
	this.audioPlayNext.delay(delayTime, this);
	
};
// Event return to play second note after first is done
//
MainIntervalAssistant.prototype.audioPlayNext = function(env) {
	Mojo.Log.info("In audioPlayNext");
	env.myAudioObj2.play();
};

// Select Cleff for Quiz
// 1=Trebel
// 2=Bass
// 3=Random
MainIntervalAssistant.prototype.getClef = function() {
	cleff = this.intStats.qClef;
	Mojo.Log.info("Selected Cleff:" + cleff);

	if (cleff == 3) {
		Mojo.Log.info("in Random Clef");
		this.selClef = Math.floor(Math.random() * 2);
	} else {
		this.selClef = cleff;
	}

};

// Select Random Note
MainIntervalAssistant.prototype.getNote = function() {
	Mojo.Log.info("Entering GetNote::");
	selNote = "";
	selIndex = 0;
	var subBassNotes = bssNotes.slice(0, 6);
	var subTrebleNotes = trbNotes.slice(0, 6);

	Mojo.Log.info("sel vs this.sel " + selNote + " " + this.selNote);
	while (this.selNote == selNote || selNote == "") {
		if (this.selClef == 1) {
			selIndex = Math.floor(Math.random() * subTrebleNotes.length);
			selNote = subTrebleNotes[selIndex];
		} else {
			selIndex = Math.floor(Math.random() * subBassNotes.length);
			selNote = subBassNotes[selIndex];
		}
	}

	// Another thing i should fix this is ugly
	this.selNoteIndex = selIndex;
	Mojo.Log.info("selNote Location " + selNote.Location);
	Mojo.Log.info("Exiting GetNote::");
	return selNote;

};

MainIntervalAssistant.prototype.checkChoice = function(event) {
	Mojo.Log.info("In Check Choice: " + event.model.value);
	var selection = event.model.value;
	var noteKey = this.selInterval.iID;

	Mojo.Log.info("CheckChoice::Selection: " + selection + " key: " + noteKey);
	// this.stopTimer();
	if (selection == noteKey) {
		this.controller.showAlertDialog( {
			onChoose : function(value) {
				this.correctChoice();
			},
			title : $L("You are correct!!"),
			choices : [ {
				label : $L('Continue'),
				value : "ok"
			} ]
		});
	} else {
		this.controller.showAlertDialog( {
			onChoose : function(value) {
				this.incorrectChoice();
			},
			title : $L("Wrong!"),
			message : $L("Correct Value: " + noteKey),
			choices : [ {
				label : $L('Continue'),
				value : "ok"
			} ]
		});
	}
	Mojo.Log.info("Exiting CheckChoice::");
};

MainIntervalAssistant.prototype.correctChoice = function() {
	// Set Array for Correct Choice
	this.intStats.qAnswers[this.qCount] = "1";
	this.nextQuestion();
};

MainIntervalAssistant.prototype.incorrectChoice = function() {
	// Set Array for Incorrect Choice
	this.intStats.qAnswers[this.qCount] = "0";
	this.nextQuestion();
};

MainIntervalAssistant.prototype.endQuiz = function() {
	// this.stopTimer();
	Mojo.Controller.stageController.swapScene("QuizEnd", this.intStats);

};

MainIntervalAssistant.prototype.createChoices = function() {
	Mojo.Log.info("Choices Length: " + this.intList.length);
	this.radioAttribs.choices = [];
	for (z = 0; z < this.intList.length; z++) {
		this.radioAttribs.choices[z] = {};
		Mojo.Log.info("Setting Choices Button:" + this.intList[z].iID);
		this.radioAttribs.choices[z].label = this.intList[z].iID;
		this.radioAttribs.choices[z].value = this.intList[z].iID;
	}

	this.radioModel.value = "";
	this.controller.modelChanged(this.radioModel);

	Mojo.Log.info("Exit CreateChoices::");
};

MainIntervalAssistant.prototype.activate = function(event) {
	/*
	 * put in event handlers here that should only be in effect when this scene
	 * is active. For example, key handlers that are observing the document
	 */
	Mojo.Event.listen(this.controller.get("choiceButtons"),
			Mojo.Event.propertyChange, this.checkChoice.bind(this));
};

MainIntervalAssistant.prototype.deactivate = function(event) {
	/*
	 * remove any event handlers you added in activate and do any other cleanup
	 * that should happen before this scene is popped or another scene is pushed
	 * on top
	 */
	Mojo.Event.stopListening(this.controller.get("choiceButtons"),
			Mojo.Event.propertyChange, this.checkChoice.bind(this));
};

MainIntervalAssistant.prototype.cleanup = function(event) {
	/*
	 * this function should do any cleanup needed before the scene is destroyed
	 * as a result of being popped off the scene stack
	 */
};


Array.prototype.findIndex = function(value) {
	var ctr = "";
	for ( var i = 0; i < this.length; i++) {
		// use === to check for Matches. ie., identical (===), ;
		if (this[i] == value) {
			return i;
		}
	}
	return ctr;
};
